import requests
from bs4 import BeautifulSoup

urll='https://movie.douban.com/top250'

h={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'}

r=requests.get(urll,headers=h)
html=r.content.decode()

soup=BeautifulSoup(html,'lxml')
divhd=soup.find_all('div',{'class':'info'})

for i in divhd:
    h={}
    h['电影']=i.find('div',{'class':'hd'}).select('span')[0].string
    h['评分']=i.find('div',{'class':'star'}).select('span')[1].string
    h['链接']=i.find('div',{'class':'hd'}).find('a')['href']
    with open('douban.txt','a',encoding='utf-8') as f:
        f.write(h.__str__()+"\n")
